package top.infopub.mgr.sts.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import top.infopub.generic.GenericDao;
import top.infopub.generic.GenericServiceImpl;
import top.infopub.mgr.sts.dao.OrgAreaQaDao;
import top.infopub.mgr.sts.domain.QaConsoleDomain;
import top.infopub.mgr.sts.service.OrgAreaQaService;
import top.infopub.mgr.util.DateUtils;
import top.infopub.model.sts.OrgAreaQa;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Maps;

@Service
public class OrgAreaQaServiceImpl extends GenericServiceImpl<OrgAreaQa, String> implements
		OrgAreaQaService {

	@Autowired
	private OrgAreaQaDao orgAreaQaDao;
	
	@Override
	public GenericDao<OrgAreaQa, String> getDao() {
		return orgAreaQaDao;
	}

    @Override
    public List<QaConsoleDomain> selectQaAreaByWhere(Date stsMonth, String hrOrgAreaId) {
        Map<String, Object> where = Maps.newHashMap();
        where.put("stsMonthStart", stsMonth);
        Date stsMonthEnd = DateUtils.getMonthEnd(stsMonth);
        where.put("stsMonthEnd", stsMonthEnd);
        where.put("hrOrgAreaId", hrOrgAreaId);
        return orgAreaQaDao.selectQaConsoleByWhere(where);
    }

    @Override
    public Page<QaConsoleDomain> selectSelfCaeAreaByWhere(Page<QaConsoleDomain> page, Date stsMonth, String orgId) {
        Map<String, Object> where = Maps.newHashMap();
        where.put("stsMonthStart", stsMonth);
        Date stsMonthEnd = DateUtils.getMonthEnd(stsMonth);
        where.put("stsMonthEnd", stsMonthEnd);
        where.put("aimType", "1");
        where.put("hrOrgSuperId", orgId);
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return (Page<QaConsoleDomain>)orgAreaQaDao.selectQaConsoleByWhere(where);
    }

    @Override
    public Page<QaConsoleDomain> selectTargetAreaByWhere(Page<QaConsoleDomain> page, Date stsMonth,
                                                         String orgId, String aimType) {
        Map<String, Object> where = Maps.newHashMap();
        where.put("stsMonthStart", stsMonth);
        Date stsMonthEnd = DateUtils.getMonthEnd(stsMonth);
        where.put("stsMonthEnd", stsMonthEnd);
        where.put("aimType", aimType);
        where.put("hrOrgSuperId", orgId);
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return (Page<QaConsoleDomain>)orgAreaQaDao.selectQaConsoleByWhere(where);
    }

    @Override
    public List<QaConsoleDomain> selectQaRateByWhere(Date stsMonth, String hrOrgAreaId) {
        Map<String, Object> where = Maps.newHashMap();
        where.put("stsMonthStart", stsMonth);
        Date stsMonthEnd = DateUtils.getMonthEnd(stsMonth);
        where.put("stsMonthEnd", stsMonthEnd);
        where.put("hrOrgAreaId", hrOrgAreaId);
        return orgAreaQaDao.selectQaRateByWhere(where);
    }

    @Override
    public List<QaConsoleDomain> selectQaAmountByWhere(Integer belongsYear, String hrOrgAreaId,
                                                       String aimType) {
        Map<String, Object> where = Maps.newHashMap();
        where.put("belongsYear", belongsYear);
        where.put("aimType", Integer.parseInt(aimType));
        where.put("hrOrgAreaId", hrOrgAreaId);
        return orgAreaQaDao.selectQaAmountByWhere(where);
    }

}